package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojo.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理的API接口", tags = "频道管理的API接口")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    @ApiOperation("根据频道名分页查询频道列表")
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return this.adChannelService.findByNameAndPage(dto);
    }

    @ApiOperation(value = "添加新频道",notes = "该方法的详细描述信息")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return adChannelService.insert(channel);
    }

    @ApiOperation(value = "修改频道",notes = "该方法的详细描述信息")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return adChannelService.update(channel);
    }

    @ApiOperation(value = "根据id删除频道",notes = "该方法的详细描述信息")
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }

}
